package com.yf.mp.controller;

import cn.hutool.core.bean.BeanUtil;
import com.yf.mp.domain.User;
import com.yf.mp.dto.PageDTO;
import com.yf.mp.dto.UserFormDTO;
import com.yf.mp.query.UserQuery;
import com.yf.mp.service.UserService;
import com.yf.mp.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/*********************************************************
 **
 ** <br><br>
 ** @ClassName: UserController
 ** @author: yangfeng
 ** @date: 2024/11/27 10:41
 ** @version: 1.0.0
 *********************************************************/
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
@Api(tags = "用户管理接口")
public class UserController {
    private final UserService userService;
    @ApiOperation("根据id查询用户信息")
    @GetMapping("/getUserById/{id}")
    public User getUserById(@PathVariable Long id){
        return userService.getById(id);
    }

    @PostMapping
    @ApiOperation("新增用户")
    public void saveUser(@RequestBody UserFormDTO userFormDTO){
        // 1.转换DTO为PO
        User user = BeanUtil.copyProperties(userFormDTO, User.class);
        // 2.新增
        userService.save(user);
    }

    @GetMapping("/page")
    @ApiOperation("分页获取用户信息")
    public PageDTO<UserVO> queryUsersPage(UserQuery query){
        return userService.queryCustomUsersPage(query);
    }


}
